# Test creating an D10 MXF file.

include("${TEST_SOURCE_DIR}/../testing.cmake")


function(run_test test frame_rate)
    if(TEST_MODE STREQUAL "check")
        set(output_file test.mxf)
    elseif(TEST_MODE STREQUAL "samples")
        set(output_file ${BMX_TEST_SAMPLES_DIR}/test_${test}_${frame_rate}.mxf)
    else()
        set(output_file test.mxf)
    endif()

    set(create_command ${RAW2BMX}
        --regtest
        -t d10
        -y 10:11:12:13
        -f ${frame_rate}
        --clip test
        -o ${output_file}
        -a 16:9 --${test} video
        -q 16 --pcm audio
        -q 16 --locked true --pcm audio
    )

    run_test_a(
        "${TEST_MODE}"
        "${BMX_TEST_WITH_VALGRIND}"
        "${create_test_video}"
        "${create_test_audio}"
        ""
        "${create_command}"
        ""
        ""
        ""
        "${output_file}"
        "${test}_${frame_rate}.md5"
        ""
        ""
    )
endfunction()


if(TEST_MODE STREQUAL "samples")
    file(MAKE_DIRECTORY ${BMX_TEST_SAMPLES_DIR})
endif()


set(create_test_audio ${CREATE_TEST_ESSENCE}
    -t 1
    -d 3
    audio
)

set(tests
    d10_30 25 13
    d10_30 2997 13
    d10_40 25 12
    d10_40 2997 12
    d10_50 25 11
    d10_50 2997 11
)

list(LENGTH tests len_tests)
math(EXPR max_index "(${len_tests} / 3) - 1")

foreach(index RANGE ${max_index})
    math(EXPR test_index "${index} * 3")
    list(GET tests ${test_index} test)
    
    math(EXPR test_frame_rate_index "${index} * 3 + 1")
    list(GET tests ${test_frame_rate_index} test_frame_rate)

    math(EXPR test_ess_type_index "${index} * 3 + 2")
    list(GET tests ${test_ess_type_index} test_ess_type)

    set(create_test_video ${CREATE_TEST_ESSENCE}
        -t ${test_ess_type}
        -d 3
        video
    )

    run_test(${test} ${test_frame_rate})
endforeach()
